from selenium import webdriver
import xlrd
import time
from testcase.project import add

class read:

    def read_casedata_execl(self,tablesheet):
        casefile = "pro.xls"
        data = xlrd.open_workbook(casefile)
        casetablesheet = data.sheet_by_name(tablesheet)
        keys = casetablesheet.row_values(0)
        rowNum = casetablesheet.nrows  # 总行数
        colNum = casetablesheet.ncols  # 总列数
        if rowNum <= 1:
            print("无测试用例数据")
            return None
        else:
            r = []
            j = 1
            for i in range(rowNum - 1):
                s = {}
                values = casetablesheet.row_values(j)
                # print(values)
                for x in range(colNum):
                    s[keys[x]] = values[x]
                r.append(s)
                # print(r)
                j += 1
            return r

    def dictlistdata_to_list(self,listdict):
        casedata = []
        for line in listdict:
            linetupe = tuple(line.values())
            linelist = list(linetupe)
            tempstr = ','.join(linelist)
            casedata.append(tempstr)
        print(casedata)
        return casedata

if __name__ == '__main__':
    class2 = read()
    list = class2.dictlistdata_to_list(class2.read_casedata_execl('Agile1'))
    for i in list:
        startdata, finishdata, content = i.split(',')
        add().do_add(startdata, finishdata, content)
